﻿// -----------------------------------------------------------------------
// <copyright file="Histogram.cs" company="Microsoft">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace ImageP
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class Histogram
    {
        /// <summary>
        /// draws a histogram representing the intensity of each color in the image.
        /// </summary>
        /// <param name="type">type</param>
        /// <param name="imageHeight">imageHeight</param>
        /// <param name="imageWidth">imageWidth</param>
        /// <param name="image">image</param>
        /// <returns>int []</returns>
        public int[] DrawHistogram(string type, int imageHeight, int imageWidth, Image image)
        {
            Bitmap buffer = new Bitmap(image);
            int[] allColors = new int[256];
            int[] red = new int[256];
            int[] green = new int[256];
            int[] blue = new int[256];
            int value = 0;
            for (int i = 0; i < imageHeight; i++)
            {
                for (int j = 0; j < imageWidth; j++)
                {
                    if (type == "All colors")
                    {
                        value = buffer.GetPixel(j, i).R;
                        allColors[value]++;
                        value = buffer.GetPixel(j, i).G;
                        allColors[value]++;
                        value = buffer.GetPixel(j, i).B;
                        allColors[value]++;
                    }
                    else if (type == "Red")
                    {
                        value = buffer.GetPixel(j, i).R;
                        red[value]++;
                    }
                    else if (type == "Green")
                    {
                        value = buffer.GetPixel(j, i).G;
                        green[value]++;
                    }

                    if (type == "Blue")
                    {
                        value = buffer.GetPixel(j, i).B;
                        blue[value]++;
                    }
                }
            }

            if (type == "Red")
            {
                return red;
            }
            else if (type == "Green")
            {
                return green;
            }
            else if (type == "Blue")
            {
                return blue;
            }
            else
            {
                return allColors;
            }
        }
    }
}
